<template>
  <div class="box">
    <el-button type="primary" @click="reouteLink">About</el-button>
  </div>
  <div class="box">
    <el-table :data="tableData">
      <el-table-column prop="date" label="Date" width="180" />
      <el-table-column prop="name" label="Name" width="180" />
      <el-table-column prop="address" label="Address" />
    </el-table>
  </div>
  <div class="box">
    <el-pagination layout="prev, pager, next, jumper, ->, total" :page-sizes="[100, 200, 300, 400]"
      @size-change="handleSizeChange" v-model:current-page="page.currentPage" v-model:page-size="page.pageSize"
      :total="page.total" @current-change="handleCurrentChange" />

  </div>
</template>
<script setup>
import { onMounted, reactive } from 'vue'
import { useRouter } from 'vue-router'
import { getList } from '../api/index'
const router = useRouter()
const page = reactive({
  currentPage: 1,
  pageSize: 10,
  total: 100
})
const tableData = [
  {
    date: '2016-05-03',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-02',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-04',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
  {
    date: '2016-05-01',
    name: 'Tom',
    address: 'No. 189, Grove St, Los Angeles',
  },
]
const getData = () => {
  const { currentPage, pageSize, total } = page
  const params = {
    currentPage,
    pageSize,
    total
  }
  getList(params).then(res => {
    console.log(res)
  })
}
const handleSizeChange = (newSize) => {
  page.pageSize = newSize;
  getData();
};

const handleCurrentChange = (newPage) => {
  page.currentPage = newPage;
  getData();
};

onMounted(() => {
  getData
})
const reouteLink = () => {
  router.push('/about')
}
</script>

<style scoped lang="scss">
.box {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 20px;
  background: $color;
  color: #f00;;
}
</style>
